package com.weseal.form;

import com.weseal.domain.PartDate;
import com.weseal.domain.PartInfo;
import com.weseal.enums.PartStatus;
import org.joda.time.DateTime;
import org.joda.time.Days;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author
 */
public class PartInfoForm implements Serializable {
	private static final long serialVersionUID = 1L;
	private Long id;
	/**
	 * 标题
	 */
	private String title;
	/**
	 * 详细信息
	 */
	private String detail;
	/**
	 * 单天薪资
	 */
	private Double salary;
	/**
	 * 单天人数
	 */
	private Integer peopleNumber;
	/**
	 * 开始日期
	 */
	private Date startTime;
	/**
	 * 结束日期
	 */
	private Date endTime;
	/**
	 * 公司名称
	 */
	private String companyName;
	/**
	 * 周期
	 */
	private String cycle;
	/**
	 * 创建日期
	 */
	private Date createTime;
	/**
	 * 修改日期
	 */
	private Date updateTime;
	/**
	 * 创建人
	 */
	private Long createUserId;
	/**
	 * 修改人
	 */
	private Long updateUserId;
	/**
	 * 备注
	 */
	private String remark;

	private String province;

	private String city;

	private String town;

	private String road;

	private String address;

	private Long partTypeId;

	/**
	 * 状态
	 */
	private Integer status;

	private List<String> partTimes;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getDetail() {
		return detail;
	}

	public void setDetail(String detail) {
		this.detail = detail;
	}

	public Double getSalary() {
		return salary;
	}

	public void setSalary(Double salary) {
		this.salary = salary;
	}

	public Integer getPeopleNumber() {
		return peopleNumber;
	}

	public void setPeopleNumber(Integer peopleNumber) {
		this.peopleNumber = peopleNumber;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getCycle() {
		return cycle;
	}

	public void setCycle(String cycle) {
		this.cycle = cycle;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public Long getCreateUserId() {
		return createUserId;
	}

	public void setCreateUserId(Long createUserId) {
		this.createUserId = createUserId;
	}

	public Long getUpdateUserId() {
		return updateUserId;
	}

	public void setUpdateUserId(Long updateUserId) {
		this.updateUserId = updateUserId;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public List<String> getPartTimes() {
		return partTimes;
	}

	public void setPartTimes(List<String> partTimes) {
		this.partTimes = partTimes;
	}

	public String getProvince() {
		return province;
	}

	public void setProvince(String province) {
		this.province = province;
	}

	public String getCity() {
		return city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public String getTown() {
		return town;
	}

	public void setTown(String town) {
		this.town = town;
	}

	public String getRoad() {
		return road;
	}

	public void setRoad(String road) {
		this.road = road;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}

	public Long getPartTypeId() {
		return partTypeId;
	}

	public void setPartTypeId(Long partTypeId) {
		this.partTypeId = partTypeId;
	}

	public PartStatus getStatus() {
		return PartStatus.getByCode(status);
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public PartInfo convert2Domain() {
		PartInfo partInfo = new PartInfo();
		BeanUtils.copyProperties(this, partInfo);
		return partInfo;
	}

	public List<PartDateForm> convert2PartDateDomain() {
		List<PartDateForm> partDates = new ArrayList<PartDateForm>();
		DateTime startDateTime = new DateTime(startTime);
		DateTime endDateTime = new DateTime(endTime);
		int dayCount = Days.daysBetween(startDateTime, endDateTime).getDays();
		for (int i = 0; i < dayCount; i++) {
			DateTime tempDateTime = startDateTime.plusDays(i);
			PartDateForm partDate = new PartDateForm();
			partDate.setDate(tempDateTime.toDate());
			partDate.setEstimateNumber(peopleNumber);
			partDate.setPrice(salary);
			partDate.setRealNumber(0);
			partDate.setPartId(id);
			partDates.add(partDate);
		}
		return partDates;
	}
}